package com.jxw.utils;

import android.util.Log;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/* loaded from: classes.dex */
public class GlobalThreadPools {
    private static final int CORE_POOL_SIZE;
    private static final int KEEP_ALIVE_SECONDS = 60;
    private static final int MAXIMUM_POOL_SIZE;
    private static ExecutorService THREAD_POOL_EXECUTOR;
    private static GlobalThreadPools instance;
    private static final BlockingQueue<Runnable> sPoolWorkQueue;
    private static final ThreadFactory sThreadFactory;
    private static String TAG = GlobalThreadPools.class.getSimpleName();
    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();

    static {
        int i = CPU_COUNT;
        CORE_POOL_SIZE = i;
        MAXIMUM_POOL_SIZE = i * 2;
        sPoolWorkQueue = new LinkedBlockingQueue(i);
        sThreadFactory = new ThreadFactory() { // from class: com.jxw.utils.GlobalThreadPools.1
            private final AtomicInteger mCount = new AtomicInteger(1);

            @Override // java.util.concurrent.ThreadFactory
            public Thread newThread(Runnable runnable) {
                return new Thread(runnable, "MangoTask #" + this.mCount.getAndIncrement());
            }
        };
    }

    private void initThreadPool() {
        THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, 60L, TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory, new RejectedHandler()) { // from class: com.jxw.utils.GlobalThreadPools.2
            @Override // java.util.concurrent.ThreadPoolExecutor, java.util.concurrent.Executor
            public void execute(Runnable runnable) {
                super.execute(runnable);
                String str = GlobalThreadPools.TAG;
                Log.e(str, "ActiveCount=" + getActiveCount());
                String str2 = GlobalThreadPools.TAG;
                Log.e(str2, "PoolSize=" + getPoolSize());
                String str3 = GlobalThreadPools.TAG;
                Log.e(str3, "Queue=" + getQueue().size());
            }
        };
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class RejectedHandler implements RejectedExecutionHandler {
        @Override // java.util.concurrent.RejectedExecutionHandler
        public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) {
        }

        private RejectedHandler() {
        }
    }

    private GlobalThreadPools() {
        initThreadPool();
    }

    public static GlobalThreadPools getInstance() {
        if (instance == null) {
            instance = new GlobalThreadPools();
        }
        return instance;
    }

    public void execute(Runnable runnable) {
        THREAD_POOL_EXECUTOR.execute(runnable);
    }
}
